<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'internet.jsp' starting page</title>
    
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/1.3.4/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/wu.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/icon.css" />
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/1.3.4/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/1.3.4/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript">
		$(function(){
			var msg = $("#msg").val();
			if(msg!=""){
				$.messager.show({
					title:'消息',
					msg:msg
				});
				$("#msg").val("");
			}
			$('#dg').datagrid({   
			    url:'${pageContext.request.contextPath}/inter?op=showinter',
			    fitColumns:true,   
			    singleSelect:true,
			    columns:[[   
			        {field:'name',title:'网址名称',width:40},   
			        {field:'address',title:'网址',width:100},   
			        {field:'id',title:'操作',width:20,align:'center',
			        	formatter:function(value,row,index){
			        		return "<a href='javascript:updateInter("+value+")'>修改</a> <a href='javascript:deleteInter("+value+")'>删除</a>";
			        	}
			        }   
			    ]],
			    pagination:true,
			    toolbar:[
			    {
					text:'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 常 用 网 址 列 表',
				},{
					text:'添加',
					iconCls: 'icon-add',
					handler: function(){
						$("form").removeAttr('style').attr('action','${pageContext.request.contextPath}/inter?op=addinter');
						$('#win').window({
							title:'添加网址',   
						    width:400, 
						    height:230,   
						    modal:true  
						}); 
					},
				} ,
				 '-', {
				 	text:'返回主页',
					iconCls : 'icon-undo',
					handler : function() {
						location.href='${pageContext.request.contextPath}/mydesk.jsp';
						//history.go(-1);
					}
				}],
				onDblClickRow:function(rowIndex, rowData){
					window.open(rowData.address,'','height=500,width=611,scrollbars=yes,status =yes')
				}
			});  
			$(".datagrid-toolbar td:first").css('width','1100px').css('font-weight','bolder');
		});
		function updateInter(id){
			$("form").removeAttr('style').attr('action','${pageContext.request.contextPath}/inter?op=updateinter&id='+id);
			var data = $('#dg').datagrid('getSelected');
			$("input[name='name']").val(data.name);
			$("input[name='address']").val(data.address);
			$('#win').window({
				title:'修改网址',   
			    width:400, 
			    height:230,   
			    modal:true  
			}); 
		}
		function deleteInter(id){
			if(confirm("确认删除吗？")){
				window.location.href="${pageContext.request.contextPath}/inter?op=deleteinter&id="+id;
			}
		}
	</script>
	<style type="text/css">
		#formtable{
			margin: 20px
		}
		#formtable td{
			padding: 10px
		}
		
	</style>
  </head>
  
  <body>
  <input type="hidden" name="msg" id="msg" value="${msg }">  
    <table id="dg"></table> 
    <div id="win">
    	<form action="" method="post" style="display: none">
    		<table id='formtable'>
    			<tr>
    				<td>网址名称:</td>
    				<td><input name="name" value="" type="text" size="30"/></td>
    			</tr>
    			<tr>
    				<td>地址</td>
    				<td><input name="address" value="" type="text" size="30"/></td>
    			</tr>
    			<tr>
    				<td></td>
    				<td><input type="submit" value="保存"/></td>
    			</tr>
    		</table>
    	</form>
    </div>   
  </body>
</html>
